﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace MyDesktopMicroBlog.Converter
{
    [ValueConversion(typeof(int), typeof(bool))]
    public class IntToIsEnabledConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (int.Parse(value.ToString()) <=0)
            {
                return false;
            }
            try
            {
                string[] parameters = parameter.ToString().Split(':');
                int expectedlength = int.Parse(parameters[1]);
                if (parameters[0] == "lessthan")
                {
                    return int.Parse(value.ToString()) < expectedlength;
                }
                else
                {
                    return int.Parse(value.ToString()) > expectedlength;
                }
            }
            catch
            {
                throw;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
